package com.jz.netthings.core.repository.config;

import com.baomidou.mybatisplus.entity.GlobalConfiguration;
import com.baomidou.mybatisplus.enums.IdType;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author yyy
 * @ClassName MybatisPlusConfig
 * @Description MybatisPlus 自动配置类
 * @date 2018/7/30 22:41
 */
@Configuration
@EnableTransactionManagement
@MapperScan(basePackages = {"com.jz.netthings.**.dao.mysql","com.jz.netthings.**.mapper.mysql"}, sqlSessionTemplateRef = "mySql_sqlSessionTemplate")
public class MybatisPlusConfig {

    /**
     * mybatis-plus分页插件<br>
     * 文档：http://mp.baomidou.com<br>
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        paginationInterceptor.setLocalPage(true);// 开启 PageHelper 的支持

        return paginationInterceptor;
    }

    /**
     * mybatis-plus 全局配置
     * @return
     */
    @Bean
    public GlobalConfiguration globalConfiguration(){
        GlobalConfiguration globalConfiguration = new GlobalConfiguration();

        globalConfiguration.setDbColumnUnderline(true);
        globalConfiguration.setIdType(IdType.AUTO.getKey());

        return globalConfiguration;
    }
}
